<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Grom Hellscream
 * Date: 11/2/12
 * Time: 11:06 AM
 * To change this template use File | Settings | File Templates.
 */
defined('_JEXEC') or die;


/**
 * @package		Joomla.Administrator
 * @subpackage	mod_vast_menu
 */
abstract class modVastMenuHelper
{
    static function getVienInfo()
    {
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);
        $query->select('a.*');
        $query->from('#__vien AS a');
        $query->where('published = 1');
        
        $db->setQuery($query);
        
        return $db->loadObject();        
    }

    static function getHosocanbo()
    {
		$user = JFactory::getUser();
        $id = $user->id;

        $db = JFactory::getDBO();
        $query = $db->getQuery(true);

        $query->select('DISTINCT a.*, b.lanhdao, b.donvi_id, b.phong_id, c.ten AS tendonvi, d.ten AS tenphong');
        $query->from('#__hosocanbo AS a');
        $query->join('LEFT', '#__congtac AS b ON b.hosocanbo_id = a.id');
        $query->join('LEFT', '#__donvi AS c ON c.id = b.donvi_id');
        $query->join('LEFT', '#__phong AS d ON d.id = b.phong_id');
        
        $query->where('a.nguoidung_id = ' . $id);

        $db->setQuery($query);
        $canbo = $db->loadObject();

        return $canbo;        
    } 
    
    static function getPhongLanhDao()
    {
		$user = JFactory::getUser();
        $id = $user->id;

        $db = JFactory::getDBO();
        $query = $db->getQuery(true);

        $query->select('DISTINCT a.*, c.id AS phongid');
        $query->from('#__hosocanbo AS a');
        $query->join('INNER', '#__congtac AS b ON b.hosocanbo_id = a.id');
        $query->join('INNER', '#__phong AS c ON c.id = b.phong_id');
        
        $query->where('a.nguoidung_id = ' . $id);
        $query->where('b.lanhdao = 1 AND b.taivi = 1');

        $db->setQuery($query);
        $result = $db->loadObject();
        
        return $result;        
    }       
    
    static function getDonViLanhDao()
    {
		$user = JFactory::getUser();
        $id = $user->id;

        $db = JFactory::getDBO();
        $query = $db->getQuery(true);

        $query->select('DISTINCT a.*, c.id AS donviid');
        $query->from('#__hosocanbo AS a');
        $query->join('INNER', '#__congtac AS b ON b.hosocanbo_id = a.id');
        $query->join('INNER', '#__donvi AS c ON c.id = b.donvi_id');
        
        $query->where('a.nguoidung_id = ' . $id);
        $query->where('b.lanhdao = 1 AND b.taivi = 1');

        $db->setQuery($query);
        $result = $db->loadObject();
        
        return $result;        
    }           
}
